// https://www.bilibili.com/video/BV1d54y1f7B3?spm_id_from=333.788.videopod.episodes&vd_source=d6fe65f095f01f05591e89d810720ccc&p=30
// 2024-10-23

public class P034_字符串搜索_暴力法 {

    public static void main(String[] args) {
        String txt = "ABCABCAABCABCD";
        String pat = "ABCABCD";

        System.out.println(BF(txt,pat));
    }

    private static int BF(String txt, String pat) {
        for (int i = 0; i <= txt.length()-pat.length(); i++) {
            int j = 0;
            for (; j < pat.length(); j++) if (pat.charAt(j) != txt.charAt(i+j)) break;
            if (j == pat.length()) return i;   //子串全部匹配完了
        }
        return -1;
    }

}
